import redis


class RedisTools:
    def __init__(self, host='localhost', port=6379, decode_responses=True):
        pool = redis.ConnectionPool(host=host, port=port, decode_responses=decode_responses)
        self.r = redis.Redis(connection_pool=pool)

    def set(self, key, value):
        if not isinstance(value, str):
            value = str(value)
        self.r.set(key, value)

    def get(self, key):
        return self.r.get(key)

    def delete(self, key):
        self.r.delete(key)

    def keys(self, pattern):
        return self.r.keys(pattern)

    def exists(self, key):
        return self.r.exists(key)
